package com.badger.pattern.factory;

/**
 * 抽象工厂
 * @author liqi
 *
 */
public class TestAbsFactory {
    public static void main(String[] args) {
        AbsIceCreamFactory factory = new ShangHaiIceCreamFactory();
        IceCream ice = factory.buildIceCream(1);
        System.out.println(ice.getName() + "----" + ice.getFlavor());
        factory = new HangZhouIceCreamFactory();
        IceCream ice1 = factory.buildIceCream(1);
        System.out.println(ice1.getName() + "----" + ice1.getFlavor());
    }

}

/**
 * 抽象工厂
 * @author liqi
 *
 */
abstract class AbsIceCreamFactory {
    abstract IceCream buildIceCream(int i);
}

/**
 * 具体的上海工厂
 * @author liqi
 *
 */
class ShangHaiIceCreamFactory extends AbsIceCreamFactory {
    @Override
    IceCream buildIceCream(int i) {
        IceCream ice;
        switch (i) {
        case 1:
            ice = new SuiBianIceCream("随变冰淇淋", "酸的");
            break;
        default:
            ice = new OldIceCream("老冰棍", "甜的的");
            break;
        }
        return ice;
    }

}

/**
 * 具体的杭州工厂
 * @author liqi
 *
 */
class HangZhouIceCreamFactory extends AbsIceCreamFactory {
    @Override
    IceCream buildIceCream(int i) {
        IceCream ice;
        switch (i) {
        case 1:
            ice = new SuiBianIceCream("随变冰淇淋", "甜的");
            break;
        default:
            ice = new OldIceCream("老冰棍", "咸的");
            break;
        }
        return ice;
    }

}
